package com.zsqat.eshop.order.config;

import com.alibaba.csp.sentinel.adapter.servlet.callback.WebCallbackManager;
import com.alibaba.fastjson.JSON;
import com.zsqat.common.enums.BizCodeEnum;
import com.zsqat.common.utils.R;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OrderSentinelConfig {
  public OrderSentinelConfig() {
    WebCallbackManager.setUrlBlockHandler(
      (request, response,ex) -> {
        R error = R.error(BizCodeEnum.TO_MANY_REQUEST.getCode(), BizCodeEnum.TO_MANY_REQUEST.getMessage());
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json");
        response.getWriter().write(JSON.toJSONString(error));
      }
    );
  }
}
